/*********************************RADIX SORT****************************/

import java.util.*;
public class Radix
{
	static void radixsort(int a[], int d)
	{
		int bucket[][], c[], e=1, i, j, k, m, digit, row, col;
		bucket = new int[a.length][10];

		c= new int[10];

		for(m=1;m<=d;m++)
		{
			for(i=0;i<=9;i++)
			c[i]=-1;
			
			for(i=0;i<=a.length-1;i++)
			{
				digit=(a[i]/e)%10;
				c[digit]++;	
				row=c[digit];
				col=digit;
				bucket[row][col]=a[i];
			}
		k=-1;
		for(i=0;i<=9;i++)
		{
			if(c[i]!=-1)
			{
				for(j=0;j<=c[i];j++)
				{
					k++;
					a[k]=bucket[j][i];
				}
			}
		}
		e=e*10;
		}
	}

public static void main(String args[])
{
	System.out.println("Enter number of elements");
	Scanner kbd= new Scanner(System.in);
	
	int n=kbd.nextInt();
	int a[]=new int[n];
	for(int i=0;i<=n-1;i++)
	{
		System.out.println("enter element" +(i+1));
		a[i]=kbd.nextInt();
	}
	radixsort(a,3);
	System.out.println("Sorted array is");
	for(int i=0;i<=n-1;i++)
		System.out.println(a[i]);

}
}

/*
	******************OUTPUT*******************

Enter number of elements
5
enter element1
894
enter element2
125
enter element3
451
enter element4
781
enter element5
328
Sorted array is
125
328
451
781
894
*/